﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Sundry.Common
{
    public class Md5Helper
    {
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="realMsg">需要加密的字符串</param>
        /// <returns></returns>
        public static string MD5Encrypt(string realMsg)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] encryptByte =md5.ComputeHash(Encoding.Default.GetBytes(realMsg));
            StringBuilder sb = new StringBuilder();
            foreach (var item in encryptByte)
            {
                sb.Append(item.ToString("X2"));
            }
            return sb.ToString();
        }
        /// <summary>
        /// 创建密码MD5
        /// </summary>
        /// <param name="password">需要创建的密码</param>
        /// <param name="salt">盐值</param>
        /// <returns></returns>
        public static string CreatePassword(string password, string salt)
        {
            return MD5Encrypt(string.Format("{0}{1}",password,salt));
        }
    }
}
